package unittests;

import static org.junit.Assert.*;

import java.util.ArrayList;

import junit.framework.TestCase;
import model.Employee;

import org.junit.Before;
import org.junit.Test;

import controllers.LoginController;

public class LoginTests extends TestCase{

	public ArrayList<Employee> empTest =new ArrayList<Employee>();
	
	public LoginController loginC = null;
	@Before
	public void setUp() throws Exception {
		loginC = new LoginController();
		empTest.add(new Employee("1111",1,"pit","123",2,0));
		empTest.add(new Employee("2222",2,"jacob","321",2,0));
		empTest.add(new Employee("11211",3,"gili","654",1,1));
		empTest.add(new Employee("11311",4,"moran","876",3,1));
		loginC.setEmpp(empTest);
	}

	@Test
	public void testEqualsPer() {
		//check if the position is not correct
		assertFalse(loginC.equalsPer(new Employee("12921",5,"mor","876",50,1)));
		//check if the position is  correct
		assertTrue(loginC.equalsPer(new Employee("12821",6,"moranush","876",5,1)));
	}
	
	@Test
	public void testPass(){
		String cPass = "123";
		String cUser = "pit";
		//check if the password correct
		assertTrue(loginC.checkPassword(cUser, cPass));
		//check if the password is't correct
		cPass = "1aa";
		assertFalse(loginC.checkPassword(cUser, cPass));
	}
	
	@Test
	public void testuserConnect(){
		int Cid  = 2;
		//check if the user is not connected
		assertFalse(loginC.userConnect(Cid));
		Cid = 4;
		//check if the user is connected
		assertTrue(loginC.userConnect(Cid));
		
	}
	
	public void testuserExist(){
		int Cid  = 2;
		//check if the user is exist
		assertTrue(loginC.userExist(Cid));
		Cid = 18;
		//check if the user is not exist
		assertFalse(loginC.userExist(Cid));
	}
	
	public void testchangeStatus(){
		int Cid  = 1;
		//check if the status is changed
		assertTrue(loginC.changeStatus(Cid)==(empTest.get(0).getStatus()));
		//check if the status is't changed
		assertFalse(loginC.changeStatus(2)==(1-empTest.get(1).getStatus()));
		
	}
	

}
